# -*- coding: utf-8 -*-
import xlwt
import json
# import threadpool
# 创建excel工作表
workbook = xlwt.Workbook(encoding='utf-8')
worksheet = workbook.add_sheet('sheet1')

# 设置表头
worksheet.write(0, 10, label='StateCode')
worksheet.write(0, 11, label='Reason')
worksheet.write(0, 12, label='Result')
# worksheet.write(0, 13, label='OTHER')


# 读取json文件
with open('test1.json', 'r') as f:
 data = json.load(f) #将文件加载为json格式的文件

# 将json字典写入excel
# 变量用来循环时控制写入单元格，感觉有更好的表达方式
val1 = 1
val2 = 1
val3 = 1
val4 = 1
print(type(data))
for list_item in data:
 print(type(list_item))
 # for key, value in list_item.items():
 # for key, value in data:
 for key in data:
  if key == "StataCode":
   worksheet.write(val1, 10, data[key])
   val1 += 1
  elif key == "Reason":
   worksheet.write(val2, 11, data[key])
   val2 += 1
  elif key == "Result":
   worksheet.write(val3, 12, data[key])
   val3 += 1
#   elif key == "OTHER":
#    worksheet.write(val4, 3, value)
#    val4 += 1
  else:
   pass

# 保存
workbook.save('OK1.xls')

